﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Compilex.BaseLibrary;
using Infraestruturex.BaseLibrary;

namespace Compilex.Syntatic.Descriptors
{
    public class FunctionDescriptor : SymbolDescriptor
    {
        public bool IsVoid { get; set; }
        public SymbolType ReturnType { get; set; }
        public SimpleList<VariableDescriptor> Params { get; set; }
        public SimpleList<Symbol> LocalVariables { get; set; }
        public string ReturnLabel { get; set; }
        public bool IsLibraryFunction { get; set; }
        public FunctionDescriptor()
        {
            this.Params = new SimpleList<VariableDescriptor>();
            this.LocalVariables = new SimpleList<Symbol>();
        }

        public int ReturnAddressSize
        {
            get { return 2; }
        }

        

        public int LocalVariablesStackSizeBytes
        {
            get
            {
                int size = 0;
                LocalVariables.ToArray().ForEach(var => size += ((VariableDescriptor)var.Descriptor).SizeBytes);
                return size;
            }
        }

        public int ParamsStackSize
        {

            get
            {
                int stackSize = 0;
                foreach(var param in Params.ToArray())
                {
                    stackSize += param.SizeBytes;
                }

                return stackSize;
            }

        }
    }
}
